let v = new Vue({
   el:'#update_address',
   data:{
       address:{
           uid:'',
           id:'',
           default:false,
           name:'',
           phone:'',
           address:'',
           region:''
       }
   },
    methods:{
        findAddress:function () {
            axios(`address/findAddressById/${this.address.id}/${this.address.uid}`)
                .then(rsp=>{
                    if (rsp.data.flag){
                        this.address = rsp.data.data;
                        this.address.default = rsp.data.data.default === 1;
                        document.getElementById('Map_input_callback').value = this.address.region;
                    }
                })
                .catch(error=>{
                    layer.msg(error.message);
                });
        },
        updateAddress:function () {
            this.address.region = document.getElementById('Map_input_callback').value;
            if (this.address.name === '' || this.address.phone === '' ||this.address.address === '' 
                ||this.address.region === '' ){
                layer.msg("信息填写不足，请检查");
                return false;
            }else{
                //检查手机格式是否正确
                let regPhone = /^1[3|4|5|8][0-9]\d{8}$/;
                this.isFlag = regPhone.test(this.address.phone);
                if (!this.isFlag) {
                    layer.msg("手机格式不正确，请重新填写");
                    return false;
                }else {
                    //判断是否默认设置成默认地址
                    this.address.default = this.address.default === true ? 1 : 0;
                    axios.put(`address/updateAddress`, this.address)
                        .then(rsp => {
                            if (rsp.data.flag) {
                                parent.layer.message = rsp.data.data;   //更新记录数返回给父窗口
                                let i = parent.layer.getFrameIndex(window.name);    //获取子窗口序号
                                parent.layer.close(i)//通过父窗口，根据子窗口序号关闭窗口
                            }
                        })
                        .catch(e => {
                            layer.msg(e.message);
                        });
                }
            }
        }
    },
    created:function () {
        this.address.uid = parent.layer.uid;
        this.address.id = parent.layer.aid;
        this.findAddress();
    }
});